<?php 
require_once("function/config.php");
global $adminPASS;
if (!isset($_POST['parola']) && !isset($_GET['parola'])){ require_once("template/header.php"); 
 ?>


<div id="contentas">
	<h4>Parola</h4>
	<input type="password" id="passw"  style="margin-top:10px;"></input>
	<button class="btn" id="login">Login</button>
	<img src='res/img/loading.gif' id="loading" style="display:none;margin-top:-15px;"/>
</div>
<script>

$(document).ready(function (){
	$(login).click(function(){
		$("#loading").css({"display":"visible"});
		$("#contentas").load("newsletter.php",{parola:$("#passw").val()});
	});
});
</script>


<?php 

require_once("template/footer.php"); 

} else {
	if (!isset($_POST['parola'])) $_POST['parola']=$_GET['parola'];
	if ($_POST['parola']!=$adminPASS){ ?>

	<div class="alert alert-block alert-error">
  		<h4>Parola incorecta</h4>
  		Va rugam sa mai incercati.
	</div>

<?php exit(0);} else {  	
 	/*echo "EXEC:".$db->exec("DROP TABLE email");
 	echo "EXEC:".$db->exec("CREATE TABLE email(judet text, email text, ip text)");*/
 	/*print("<table class=\"table\"><thead><tr><th>#</th><th>Judet</th><th>Email</th><th>IP</th></tr></thead><tbody>");
 	//var_dump($res);
 	$v=0;

 	while ($row=$res->fetch(PDO::FETCH_ASSOC)){
 		printf("<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>",++$v,$row['judet'],$row['email'],$row['ip']);
 	}
 	print("</tbody></table>");
 		
	}*/
	?>

		<select id="boomHS" class="span2" style="margin-top:10px;">
            <option value="Any">Orice județ</option> 
                <option value="Alba">Alba</option>
                <option value="Arad">Arad</option>
                <option value="Arges">Argeș</option>
                <option value="Bacau">Bacău</option>
                <option value="Bihor">Bihor</option>
                <option value="Bistrita Nasaud">Bistrița Năsăud</option>
                <option value="Botosani">Botoșani</option>
                <option value="Brasov">Brașov</option>
                <option value="Braila">Brăila</option>
                <option value="Bucuresti">București</option>
                <option value="Buzau">Buzău</option>
                <option value="Caras Severin">Caraș Severin</option>
                <option value="Calarasi">Călărași</option>
                <option value="Cluj">Cluj</option>
                <option value="Constanta">Constanța</option>
                <option value="Covasna">Covasna</option>
                <option value="Dambovita">Dâmbovița</option>
                <option value="Dolj">Dolj</option>
                <option value="Galati">Galați</option>
                <option value="Giurgiu">Giurgiu</option>
                <option value="Gorj">Gorj</option>
                <option value="Harghita">Harghita</option>
                <option value="Hunedoara">Hunedoara</option>
                <option value="Ialomita">Ialomița</option>
                <option value="Iasi">Iași</option>
                <option value="Ilfov">Ilfov</option>
                <option value="Maramures">Maramureș</option>
                <option value="Mehedinti">Mehedinți</option>
                <option value="Mures">Mureș</option>
                <option value="Neamt">Neamț</option>
                <option value="Olt">Olt</option>
                <option value="Prahova">Prahova</option>
                <option value="Satu Mare">Satu Mare</option>
                <option value="Salaj">Sălaj</option>
                <option value="Sibiu">Sibiu</option>
                <option value="Suceava">Suceava</option>
                <option value="Teleorman">Teleorman</option>
                <option value="Timis">Timiș</option>
                <option value="Tulcea">Tulcea</option>
                <option value="Vaslui">Vaslui</option>
                <option value="Valcea">Vâlcea</option>
                <option value="Vrancea">Vrancea</option>  
            </select>&nbsp;
			<button class="btn" id="browse">Afiseaza</button>
			<button class="btn btn-danger" id="delte">Sterga baza de date</button>
			<script>


			$(document).ready(function (){
				$("#delte").click(function(){
					$.get("truncate.php");
					window.location="newsletter.php";
				});
				$('#browse').click(function(){
					$("#contentas").load("newsletter.php",{parola:'<?php echo $adminPASS;?>',judet:$("#boomHS").val()});

				});
			});

			</script>

		<?php
		if (isset($_POST['judet'])){
			$db=new PDO('sqlite:angajati.db','','');
			$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
			
			$res=$db->prepare("SELECT * FROM email WHERE judet = ? LIMIT 10");
			if ($_POST['judet']=="Any") $_POST['judet']="";	
			$res->bindParam(1,$_POST['judet']);
	 		$res->execute();
			
	 		$v=0;
	 		print("<hr/><textarea style='width:100%;height:200px;'>");
	 		while ($row=$res->fetch(PDO::FETCH_ASSOC)){
 				printf("<%s>,",$row['email']);
 			}
 			print("</textarea>");
	 	}
	}
}